package com.road.service.imp;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.road.dao.INewsDao;
import com.road.dao.imp.NewsDaoImp;
import com.road.model.News;
import com.road.service.INewsService;
import com.road.service.ISeeService;

public class NewsServiceImp implements INewsService {
   INewsDao newsDao=new NewsDaoImp();
	@Override
	public List<News> getNewsListByConditions(News news, String page, String size) throws SQLException {
		// TODO Auto-generated method stub, int page, int size
		List<News> list=null;
		int pagenum=0,pagesize=10;
			if(page!=null)pagenum=Integer.parseInt(page);
			if(size!=null)pagesize=Integer.parseInt(size);
			list= newsDao.getNewsListByConditions(news, pagenum, pagesize);
		return list==null?new ArrayList<>():list;
	}
	
	@Override
	public boolean saveBatchNews(List<News> newsList) throws SQLException {
		// TODO Auto-generated method stub
		
		return newsDao.saveBatchNews(newsList);
	}

	@Override
	public News getNewsContent(News newsId,String phone) throws SQLException {
		// TODO Auto-generated method stub
		ISeeService ss=new SeeServiceImp();
		//获取详情时更新新闻浏览量
		newsDao.updateSeeTimesBy(newsId.getId().toString());
		//如果没有查看记录，记录此条日志	
		if(!ss.isSee(phone, newsId.getId()+"")) {
			//保存浏览记录
			ss.saveSeeTimes(phone, newsId.getId().toString());
		}
		return newsDao.getNewsContent(newsId);
	}

	@Override
	public boolean deleteBatchNewsbyId(String[] newsIds) throws SQLException {
		// TODO Auto-generated method stub
		return newsDao.deleteBatchNewsbyId(newsIds);
	}

	@Override
	public boolean updatePraiseBy(String newsIds,int addOrdel) throws SQLException {
		// TODO Auto-generated method stub
		
		return newsDao.updatePraiseBy(newsIds, addOrdel);
	}

	@Override
	public boolean updateSeeTimesBy(String newsIds) throws SQLException {
		// TODO Auto-generated method stub
		return newsDao.updateSeeTimesBy(newsIds);
	}

	@Override
	public boolean updateCommentTimesBy(String newsIds,int addOrdel) throws SQLException {
		// TODO Auto-generated method stub
		return newsDao.updateCommentTimesBy(newsIds, addOrdel);
	}

	@Override
	public int getSeeTimesOrCommentOrSeeByNewsIds(String clum,String newsIds) throws SQLException {
		// TODO Auto-generated method stub
		return newsDao.getSeeTimesOrCommentOrSeeByNewsIds(clum, newsIds);
	}

	@Override
	public List<News> getNewsListCarouselTop5() throws SQLException {
		// TODO Auto-generated method stub
		return newsDao.getNewsListCarouselTop5();
	}


}
